import { HikvisionBaseService } from "../base";
import { hikvision } from "../type";

/** 食堂消费功能接口 */
export class ConsumeCemsService extends HikvisionBaseService {
	/** 查询账户记录 */
	async getAccountLog(opts: {
		/** 开始时间，字符串格式：yyyy-MM-ddThh:mm:ss+08:00 */
		startTime: string;
		/** 结束时间，字符串格式：yyyy-MM-ddThh:mm:ss+08:00 */
		endTime: string;
		pageNo?: number;
		pageSize?: number;
		transactionTypes?: string;
		personId?: string;
	}) {
		const params = {
			...opts,
			pageNo: opts.pageNo || 1,
			pageSize: opts.pageSize || 100,
			startTime: opts.startTime,
			endTime: opts.endTime,
		};
		const url = `${this.config.baseUrl}/api/cems/v1/account/log/search`;
		const res = await this.curl<hikvision.isc.IResponse<hikvision.isc.IConsumeCemsGetAccountLogResponse>>(url, {
			method: "POST",
			dataType: "json",
			contentType: "json",
			data: {
				...params,
			},
			headers: {
				access_token: this.accessToken,
			},
		});

		this.handleResponseException(res, `查询账户记录出错`);
		return res.data.data;
	}
}
